<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目部门" prop="projectDeptId">
        <treeselect v-model="queryParams.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="资质主体" prop="projectAgencyId">
        <el-select v-model="queryParams.projectAgencyId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectagencyList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:projectextract:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:projectextract:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:projectextract:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:projectextract:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection"  align="center" />
      <el-table-column label="ID" width="40" align="center" prop="id" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目编号" align="center" prop="projectCode" />
      <el-table-column label="所属部门" align="center" prop="projectDeptName" />
      <el-table-column label="类型方式" align="center" prop="projectTypeName" />
      <el-table-column label="项目流程" align="center" prop="projectBidevaluationProcessName" />
      <el-table-column label="委托单位" align="center" prop="projectTenderee" />
      <el-table-column label="预算(万)" align="center"  >
        <template slot-scope="scope" >
          {{scope.row.projectBudget/10000}}
        </template>
      </el-table-column>
      <el-table-column label="开标时间" align="center" prop="createTime" />
      <el-table-column label="审批状态" align="center">
        <template slot-scope="scope" >
          <div v-if="scope.row.approvalStatus === 1">已审核</div>
          <div v-else >未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="数据统计(包组|投标人|中标人)"  width="130"  align="center" >
          <template slot-scope="scope" >
            0|0|0
          </template>
      </el-table-column>
      <el-table-column label="资质主体" align="center" prop="projectAgencyName" />
      <el-table-column label="项目状态" align="center" >
        <template slot-scope="scope" >
          <div v-if="scope.row.projectStatus === 1">正常</div>
          <div v-else >取消</div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:project:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>




    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%"  append-to-body>
      <el-dialog
        width="70%"
        :title="formInnerTitle"
        :visible.sync="formInnerVisible"
        append-to-body>

        <Tenderer v-if="formInnerType  === 'showProjectCode'" :getTendererRow="getProjectTendereeRow" />


      </el-dialog>

      <el-form ref="form" :model="form" :rules="rules" label-width="150px"  style="max-height: 400px; overflow-y: scroll;">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectCode">
              <el-input  v-model="form.projectCode" placeholder="请输入自行编号" style="width: 480px" >
                <el-button slot="append" type="success" @click="showProjectCode" icon="el-icon-search">从已有项目中选择</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12"  style="width: 880px">
            <el-form-item  label="项目名称" prop="projectName">
              <el-input :disabled="true" v-model="form.projectName" placeholder="请输入项目名称" style="width: 580px"  />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
              <el-form-item label="招标类型" prop="projectTypeName">
                <el-input :disabled="true" v-model="form.projectTypeName"  placeholder="请选择招标类型"   />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="招标方式" prop="projectTenderModeName">
                <el-input :disabled="true" v-model="form.projectTenderModeName" placeholder="请选择招标方式"   />
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
              <el-form-item label="评标方法" prop="projectBidevaluationModeName">
                <el-input :disabled="true" v-model="form.projectBidevaluationModeName"  placeholder="请选择评标方法"   />
              </el-form-item>
            </el-col>
          <el-col :span="12">
            <el-form-item label="资金来源" prop="projectFundingSourceName">
              <el-input :disabled="true" v-model="form.projectFundingSourceName" placeholder="请选择资金来源"    />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="委托业主" prop="projectTenderee">
              <el-input :disabled="true" v-model="form.projectTenderee" placeholder="请选择招标人" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="12">
            <el-form-item label="项目所属部门" prop="projectDeptName">
              <el-input :disabled="true" v-model="form.projectDeptName" placeholder="请选择项目所属部门" style="width: 280px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资质主体" prop="projectAgencyName">
              <el-input :disabled="true" v-model="form.projectAgencyName" placeholder="请选择招标人" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="评标时间" prop="projectBidMakeTime">

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评标地址" prop="projectBidMakeAddr">
              <el-input v-model="form.projectBidMakeAddr" placeholder="请输入评标地址" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="抽取专家地区" prop="projectImplementArea">
              <el-input :disabled="true" v-model="form.projectImplementArea" placeholder="请选择抽取专家地区" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="抽取专家数" prop="projectSectionQty">
              <el-input  v-model="form.projectSectionQty" placeholder="请输入抽取专家数" style="width: 280px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业主代表数" prop="projectBidderQty">
              <el-input  v-model="form.projectBidderQty" placeholder="请输入业主代表数" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="抽取专家类别" prop="projectExpertCateIds">
              <el-input v-model="form.projectExpertCateIds" placeholder="请选择抽取专家类别" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="回避单位" prop="noCompanyIds">
              <el-input v-model="form.noCompanyIds" placeholder="请选择回避单位" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="回避专家" prop="noExpertIds">
              <el-input v-model="form.noExpertIds" placeholder="请选择回避专家" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="从自定义专家组中抽取" prop="expertIds">
              <el-input v-model="form.expertIds" placeholder="请选择从自定义专家组中抽取" style="width: 280px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>


    </el-dialog>
  </div>
</template>

<script>
import { listProject, getProject, delProject, addProject, updateProject } from "@/api/system/projectextract";


import Treeselect from "@riophae/vue-treeselect";
import Tenderer from "@/components/Tenderer";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import User from "@/components/User";

export default {
  name: "Project",
  components: {User, Treeselect,Tenderer },
  data() {
    return {
      // 遮罩层
      formInnerVisible:false,
      formInnerType:null,
      formInnerTitle:null,
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目管理表格数据
      projectList: [],
      // 招标类型
      projecttypeList: [],
      // 招标方式
      projecttendermodeList: [],
      // 服务费付款方
      projectpayerList: [],
      // 资金来源
      projectfundingsourceList: [],
      // 项目流程
      projectbidevaluationprocessList: [],
      // 评标方法
      projectbidevaluationmodeList: [],
      // 资质主体
      projectagencyList: [],
      // 部门列表
      deptList: [],
      //列表
      companyAreaList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectBudget: null,
        projectRxpectedIncome: null,
        projectTendererId: null,
        projectTendererName: null,
        projectLeaderId: null,
        projectLeader: null,
        projectOperatorId: null,
        projectOperator: null,
        projectImplementAreaId: null,
        projectImplementArea: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAreaId: null,
        projectAreaName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        approvalStatus: null,
        projectStatus: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectBidevaluationProcessId: null,
        projectBidevaluationProcessName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectPayerId: null,
        projectPayerName: null,
        projectDeveloperId: null,
        projectDeveloper: null,
        projectDescription: null,
        projectRemark: null,
        attachmentSrc: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectTendereeContactPerson: null,
        projectTendereeContactTel: null,
        sort: null,
      },
      // 表单参数
      form: {


      },
      // 表单校验
      rules: {
      },
      projectCodeSelectList:[
        {value:1,label:"自行编号"},
        {value:2,label:"系统分配编号"},
      ]
    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询项目管理列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        isProjectCode:2,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectBudget: null,
        projectRxpectedIncome: null,
        projectTendererId: null,
        projectTendererName: null,
        projectLeaderId: null,
        projectLeader: null,
        projectOperatorId: null,
        projectOperator: null,
        projectImplementAreaId: null,
        projectImplementArea: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAreaId: null,
        projectAreaName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        approvalStatus: null,
        projectStatus: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectBidevaluationProcessId: null,
        projectBidevaluationProcessName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectPayerId: null,
        projectPayerName: null,
        projectDeveloperId: null,
        projectDeveloper: null,
        projectDescription: null,
        projectRemark: null,
        attachmentSrc: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectTendereeContactPerson: null,
        projectTendereeContactTel: null,
        projectBidMakeTime:null,
        projectBidMakeAddr:null,
        projectSectionQty:null,
        projectBidderQty:null,
        projectExpertCateIds:null,
        noCompanyIds:null,
        noExpertIds:null,
        expertIds:null,
        sort: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加专家抽取管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProject(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专家抽取管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目管理编号为"' + ids + '"的数据项？').then(function() {
        return delProject(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    },
    showProjectCode(){
      this.formInnerVisible = true;
      this.formInnerTitle = "从已有项目中选择";
      this.formInnerType = "showProjectCode";
    },
    getProjectTendereeRow(row){
      this.form.projectTendereeId =row.id;
      this.form.projectTenderee =row.tendererName;
      this.formInnerVisible = false;
    },
    getProjectDeveloperRow(row){
      this.form.projectDeveloperId =row.userId;
      this.form.projectDeveloper =row.nickName;
      this.formInnerVisible = false;
    },
    getProjectOperatorRow(row){
      this.form.projectOperatorId =row.userId;
      this.form.projectOperator =row.nickName;
      this.formInnerVisible = false;
    },
    getProjectLeaderRow(row){
      this.form.projectLeaderId =row.userId;
      this.form.projectLeader =row.nickName;
      this.formInnerVisible = false;
    },
  }
};
</script>
